﻿/// <reference path="Ext/ext-base-debug-w-comments.js" />
/// <reference path="Ext/ext-all-debug.js" />
var pendingEvents = [];
var pendingEvents2 = [];
var sendingPendent = false;
var loading;
var mask;
var njsw_token = 'ask';

Ext.Ajax.request._ID = 0;
Ext.Ajax.request.prototype.getId = function () {
    return ++Ext.Ajax.request._ID;
};
Ext.BLANK_IMAGE_URL = 'Scripts/Ext/resources/images/default/s.gif';
//Ext.enableListenerCollection = true;

Ext.grid.GridPanel.prototype.removeRows = function (start, count) {
    for (var x = start; x < start + count; x++) {
        try {
            this.getStore().removeAt(x);
        } catch (ex) { Ext.dump(ex); };
    };
};

Ext.grid.GridPanel.prototype.reloadData = function (start, limit) {
    if (this.store) {
        this.getStore().reload({ params: { start: start, limit: limit} });
    };
};

Ext.grid.EditorGridPanel.prototype.reloadData = function (start, limit) {
    if (this.store) {
        this.getStore().reload({ params: { start: start, limit: limit} });
    };
};

Ext.grid.GridPanel.prototype.UpdateIndexes = function () {
};

Ext.grid.GridPanel.prototype.ActualizarRI = function (rowcount) {
    var store = this.store;
    var __id = 0;
    for (var i = 0; i < rowcount; i++) {
        Ext.each(this.store.data.items, function (itm) {
            if (itm.data.RI == i) {
                itm.data.RI = __id++;
            };
        });
    };
};

Ext.grid.EditorGridPanel.prototype.UpdateIndexes = function () {
};

Ext.grid.EditorGridPanel.prototype.removeRows = function (start, count) {
    for (var x = start; x < start + count; x++) {
        try {
            this.getStore().remove(this.getStore().getAt(x));
        } catch (ex) { Ext.dump(ex); };
    };
};


Ext.grid.EditorGridPanel.prototype.updateCell = function (row, cell, value) {
    try {
        var _index = this.store.find("RI", row);
        if (_index > -1)
            this.store.getAt(_index).set(cell, value);
    }
    catch (ex) {//discard it?
        alert('Error', ex.Message);
    };
};

Ext.grid.GridPanel.prototype.updateCell = function (row, cell, value) {
    try {
        var _index = this.store.find("RI", row);
        if (_index > -1)
            this.store.getAt(_index).set(cell, value);
    }
    catch (ex) {//discard it?
    };
};

Ext.grid.ColumnModel.prototype.setHideAble = function (col, value) {
    try {
        this.config[col].hideable = value;
    }
    catch (ex) {//discard it?
    };
};

Ext.Viewport.prototype.setTitle = function (t) {
    document.title = t;
};

Ext.form.Checkbox.prototype.setLabel = function (text) {
    this.labelEl.dom.innerHTML = text;
};


Ext.grid.CheckColumn = function (config) {
    Ext.apply(this, config);
    if (!this.id) {
        this.id = Ext.id();
    }
    this.renderer = this.renderer.createDelegate(this);
};


Ext.grid.CheckColumn.prototype = {
    init: function (grid) {
        this.grid = grid;
        this.grid.on('render', function () {
            var view = this.grid.getView();
            view.mainBody.on('mousedown', this.onMouseDown, this);
        }, this);
    },
    onMouseDown: function (e, t) {
        if (t.className && t.className.indexOf('x-grid3-cc-' + this.id) != -1) {
            e.stopEvent();
            var index = this.grid.getView().findRowIndex(t);
            var record = this.grid.store.getAt(index);
            record.set(this.dataIndex, !record.data[this.dataIndex]);
        }
    },
    renderer: function (v, p, record) {
        p.css += ' x-grid3-check-col-td';
        return '<div class="x-grid3-check-col' +
                (v ? '-on' : '') +
               ' x-grid3-cc-' +
               this.id +
               '"> </div>';
    }
};

Ext.form.ComboBox.prototype.setTemplate = function (template) {
    if (typeof template == "string") {
        template = new Ext.XTemplate(template);
    }
    this.tpl = template;
    if (this.view) {
        this.view.tpl = template;
        this.view.refresh();
    };
};

Ext.form.ComboBox.prototype.setItemSelector = function (itemSelector) {
    this.itemSelector = itemSelector;
    if (this.view) {
        this.view.itemSelector = itemSelector;
        this.view.refresh();
    };
};

Ext.form.ComboBox.prototype.setStore = function (fields) {
    var store = new Ext.data.SimpleStore({ fields: eval('[' + fields + ']'), data: [] });
    this.store = store;
    this.bindStore(store, false);
};

//Enqueue events for server
var EnqEvs = function (ev, last) {
    var i, len;
    //We dont add the same event twice to save bandwidth
    if (last !== true && !sendingPendent) {
        for (i = 0, len = pendingEvents.length; i < len; i++) {
            if (pendingEvents[i].id == ev.id && pendingEvents[i].method == ev.method) {
                pendingEvents[i] = ev;
                return;
            };
        };
    };
    pendingEvents.push(ev);
};

var SendEvents = function () {
    sendingPendent = true;
    if (pendingEvents.length > 1) {
        var evts = [];
        while (pendingEvents.length > 0) {
            var ev = pendingEvents.shift();
            evts.push({ service: "EventsService", method: ev.method, id: 1, params: [{ Id: ev.id, Data: ev.params}], server_data: null });
        };
        SendMultiRequest(evts);
    }
    else {
        var ev = pendingEvents.shift();
        SendRequest(ev.url, ev.method, ev.id, ev.params, ev.sync === true ? true : false);
    }
    sendingPendent = false;
};

function CallBack(options, success, response) {
    if (success) {
        if (response.responseText != '') {
            var tmp = Ext.decode(response.responseText);
            if (tmp.result && tmp.result != "") {
                try {
                    if (typeof tmp.result === "function") {
                        tmp.result();
                    }
                    else {
                        eval(tmp.result);
                    }
                }
                catch (exe) {
                    if (console) {
                        console.error(exe);
                        console.info(response);
                    };
                };
            };
        };
    }
    else {
        Ext.dump(response);
    }
};

var SendMultiRequest = function (events) {
    Ext.Ajax.request({
        url: "webapp/MultiEvents.ashx",
        params: Ext.util.JSON.encode(events),
        method: "POST",
        callback: CallBack,
        showLoadIndicator: true
        , headers: { 'njsw_token': njsw_token }
    });
};

var SendRequest = function (file, _method, para, data, sync, header) {
    Ext.Ajax.request({
        url: "webapp/" + file + (sync === true ? "_sync_.ashx" : ".ashx"),
        params: Ext.util.JSON.encode([{ service: "EventsService", method: _method, id: (sync == true ? null : 1), params: [{ Id: para, Data: data}], server_data: null}]),
        method: "POST",
        callback: CallBack,
        showLoadIndicator: true,
        extraParams: { sync: sync }
        , headers: { 'njsw_token': njsw_token }
    });
    if (!sendingPendent && pendingEvents.length > 0) {
        SendEvents();
    };
};

function FileCallBack(options, success, response) {
    if (success) {
        if (response.responseText != '') {
            var tmp = response.responseText;
            if (tmp && tmp != "") {
                try {
                    eval(tmp);
                }
                catch (exe) {
                    Ext.dump(exe);
                };
            };
        };
    }
    else {
        Ext.dump(response);
    }
};

var RequestFile = function (file) {
    Ext.Ajax.request({
        url: "script/" + file,
        callback: FileCallBack,
        showLoadIndicator: true,
        extraParams: { sync: true },
        headers: [njsw_token]
        /*headers:header*/
    });
};

var RequestHello = function () {
    RequestFile('hello.js');
};

function SendToServer(file, _method, para, data, queue, sync, queued) {
    if (queue === true && !sendingPendent) {
        EnqEvs({ url: file, id: para, method: _method, params: data, sync: true }, false);
        return;
    }
    EnqEvs({ url: file, id: para, method: _method, params: data, sync: sync |= false }, true);
    SendEvents();
};

Ext.util.Format.numeric = function (v, md, r, ri, ci, st) {
    v = (Math.round((v - 0) * 100)) / 100;
    v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split('.');
    var whole = ps[0];
    var sub = ps[1] ? '.' + ps[1] : '.00';
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, '$1' + ',' + '$2');
    }
    return '' + whole + sub;
};

Ext.util.Format.numeric3 = function (v, md, r, ri, ci, st) {
    v = (Math.round((v - 0) * 1000)) / 1000;
    v = (v == Math.floor(v)) ? v + ".000" : ((v * 10 == Math.floor(v * 10)) ? v + "00" : ((v * 100 == Math.floor(v * 100)) ? v + "0" : v));
    v = String(v);
    var ps = v.split('.');
    var whole = ps[0];
    var sub = ps[1] ? '.' + ps[1] : '.000';
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, '$1' + ',' + '$2');
    }
    return '' + whole + sub;
};

ShowException = function (title, text) {
    if (Ext.isString(text) && text.length > 100) {
        var __exe = new Ext.Window({ title: title, width: 500, height: 300, modal: true, buttonAlign: 'center', maximizable: true, html: text, autoScroll: true,
            buttons: [{ text: NetJsWire.App._Exception_Close_Button_Text, handler: function () {
                __exe.close();
            }
            }
                ]
        });
        __exe.show();
    }
    else {
        Ext.MessageBox.alert(title, text);
    }
};

Ext.Ajax.on('beforerequest', function (conn, options) {
    if (loading) {
        try {
            loading.show();
        } catch (e) { };
    };
}
);

Ext.Ajax.on('requestcomplete', function (conn, response, options) {
    if (loading) {
        try {
            loading.fadeOut(.02);
        } catch (e) { };
    };
}
);
Ext.Ajax.on('requestexception', function (conn, response, options) {
    if (loading) {
        try {
            loading.fadeOut(.02);
        } catch (e) { };
    };
}
);

Ext.onReady(function () {
    Ext.QuickTips.init();
    Ext.ns("NetJsWire.App");
    NetJsWire.App._Exception_Close_Button_Text = 'Close';
    var _bd = Ext.getBody();
    SendRequest("Index", "InitComplete", "ClientDocument", { width: _bd.getWidth(), height: _bd.getHeight(false), isIE: Ext.isIE, isIE7: Ext.isIE7 }, false);
    loading = Ext.get('loading');
    mask = Ext.get('loading-mask');
    if (mask) {
        mask.setOpacity(.8);
        mask.shift({
            xy: loading.getXY(),
            width: loading.getWidth(),
            height: loading.getHeight(),
            remove: true,
            duration: 1,
            opacity: .3,
            easing: 'bounceOut',
            callback: function () {
                loading.fadeOut({ duration: .3, remove: false });
                var indicator = Ext.get('loading_indicator');
                indicator.update('');
                indicator.applyStyles('position:absolute;top:0;right:0;font-size: 8pt;background-image: url("script/Ext/resources/images/default/grid/loading.gif");background-repeat: no-repeat;background-position: top right;height: 16px;z-index:20002;background-color:transparent;');
                loading.removeClass('loading');
            }
        });
    };
});

Ext.ux.IFrameComponent = Ext.extend(Ext.BoxComponent, {
    onRender: function (ct, position) {
        this.el = ct.createChild({ tag: 'iframe', id: 'framepanel' + this.id, frameBorder: 0, src: this.url, style: { width: '100%', height: '100%'} });
    },
    setIframeUrl: function (url) {
        this.el.dom.src = url;
    }
});

var NetJsWire = function () {
    var msgCt;
    var LinkIconTemplate = new Ext.Template(
        '<div style="width:{width}px;text-align:center;position:relative;top:{top}px;left:{left}px;cursor:pointer">',
        '<img src="{src}" />',
        '<div style="font-size:0.8em">',
        '{text}',
        '</div>',
        '</div>'
        );
    LinkIconTemplate.disableFormats = true;
    LinkIconTemplate.compile();

    function createBox(t, s) {
        return ['<div class="msg">',
                '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
                '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
                '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
                '</div>'].join('');
    }

    return {
        msg: function (title, format, duration, type) {
            var iconClass = 'information';
            if (type != undefined)
                iconClass = (type == 0 ? 'information' : 'error');
            var pause = 2000;
            if (duration)
                pause = duration * 1000;
            new Ext.ux.Notification({
                title: title,
                html: format,
                iconCls: iconClass,
                autoDestroy: true,
                hideDelay: pause
            }).show(document);
        },
        OpenWindow: function (url, width, height) {
            var winWidth = 700;
            var winHeight = 400;
            if (width)
                winWidth = width;
            if (height)
                winHeight = height;
            window.open(url, "NativeWin", "width=" + winWidth + ",height=" + winHeight + ",toolBar=NO,resizable=YES", false);
        },
        LinkIcon: function (_id, config) {
            var _li = LinkIconTemplate.append(config.parent, config, true);
            _li.unselectable();
            _li.addClassOnClick("x-menu-item-active");
            return _li;
        },
        MessageBox: function (_id, caption, message, confirm) {
            if (confirm) {
                Ext.MessageBox.confirm(caption, message, function (btn) {
                    if (btn == 'yes')
                        SendToServer(_id, "Accept", _id, null, true);
                    else
                        SendToServer(_id, "Cancel", _id, null, true);

                    SendToServer(_id, "Closed", _id, null);
                });
            }
            else {
                Ext.MessageBox.alert(caption, message, function (btn) {
                    SendToServer(_id, "Closed", _id, null);
                });
            }
        },
        BasicDialog: function (config) {
            config.njsid = config.id;
            if (!config.renderTo)
                config.renderTo = document.body;
            return new Ext.ux.BasicDialog(config);
        },
        Button: function (_id, config) {
            var _divElTmp = Ext.DomHelper.append(config.parent, { id: _id + '_div', name: _id + '_div', tag: 'div', style: { position: 'absolute', top: config.top + 'px', left: config.left + 'px'} }, true);
            var btn = new Ext.Button(config);
            btn.render(_divElTmp);
            return btn;
        },
        Panel: function (_id, config) {
            var _cp_, iframe;
            if (config.useIFrame === true) {
                iframe = new Ext.ux.IFrameComponent({ url: config.url });
                config.items = [iframe];
                _cp_ = new Ext.Panel(config);
                _cp_.iframe = iframe;
                _cp_.setIframeUrl = function (url) {
                    iframe.setIframeUrl(url);
                };
            }
            else {
                _cp_ = new Ext.Panel(config);
            };
            return _cp_;
        },
        GridPanel: function (_id, config) {
            return new Ext.GridPanel(config.innerGrid);
        },
        Label: function (_id, config) {

            if (config.style == undefined)
                config.style = {};
            if (config.left)
                config.style.left = config.left + 'px';
            if (config.top)
                config.style.top = config.top + 'px';
            if (config.bottom)
                config.style.bottom = config.bottom + 'px';
            if (config.right)
                config.style.right = config.right + 'px';
            config.style.width = config.width + 'px';
            config.style.position = 'absolute';
            if (config.align) {
                config.style['text-align'] = config.align;
            };
            var _tmpLbl = Ext.DomHelper.append(config.parent, { cls: 'x-form-label-' + config.align + " label", id: _id, name: _id, tag: "span", html: config.html, style: config.style }, true);
            return _tmpLbl;

        },
        CheckBox: function (config) {
            if (!config.isInContainer) {
                var _divEltmp = Ext.DomHelper.append(config.parent, { cls: 'x-form-label', tag: "div", style: config.style }, true);
                var style = config.style;
                delete config.style;
                config.renderTo = config.parent;
            }
            var _tmpChb = new Ext.form.Checkbox(config);
            if (!config.isInContainer) {
                _tmpChb.on('check', function (chb, chkd) { SendToServer(_id, 'Check', config.id, chkd, false); });
                _tmpChb.wrap.applyStyles(style); //Ext 3
            }
            return _tmpChb;
        },
        ComboBox: function (_id, config) {
            if (!config.displayField)
                config.displayField = 'display';
            config.valueField = 'value';
            config.mode = 'local';
            var __data = config.data;
            delete config.data;
            if (!config.fields) {
                config.store = new Ext.data.ArrayStore({ idProperty: 'value', idIndex: 0, autoDestroy: true, fields: ['value', 'display'], data: __data });
            } else {
                config.store = new Ext.data.ArrayStore({ autoDestroy: true, idIndex: 0, fields: config.fields, data: __data });
            };
            var _tmpCb = new Ext.form.ComboBox(config);
            if (config.sendUpdates === true) {
                _tmpCb.on('select', function (c, r, i) { SendToServer(config.id, 'changeSelected', config.id, r.get('value')); });
            };
            return _tmpCb;
        },
        TextField: function (_id, config) {
            var _sendUpdates = config.sendUpdates;
            delete config.sendUpdates;
            var _tfTmp = new Ext.form.TextField(config);
            if (_sendUpdates === true)
                _tfTmp.on('change', function (tf, newValue, oldValue) { SendToServer(_id, 'Input', config.id, [newValue, tf.isValid()]); });
            return _tfTmp;
        },
        TextArea: function (_id, config) {
            var _sendUpdates = config.sendUpdates;
            delete config.sendUpdates;
            var _tfTmp = new Ext.form.TextArea(config);
            if (_sendUpdates === true)
                _tfTmp.on('change', function (tf, newValue, oldValue) { SendToServer(_id, 'Input', config.id, [newValue, tf.isValid()]); });
            return _tfTmp;
        },
        DateField: function (_id, config) {
            if (!config.isInContainer) {
                config.style.width = config.width + 'px';
                var style = config.style;
                delete config.style;
                if (Ext.isIE || Ext.isIE7) {
                    config.style = { top: -2, position: 'relative' };
                    config.width -= 15;
                }
            };
            var _dfTmp = new Ext.form.DateField(config);
            if (!config.isInContainer) {
                _dfTmp.wrap.applyStyles(style);
            };
            if (config.sendUpdates === true) {
                _dfTmp.on("change", function (tf, newValue, oldValue) { SendToServer(_id, "Input", config.id, tf.isValid() ? [tf.getValue().format(tf.format), true] : [tf.getRawValue(), false]); }, _dfTmp, { delay: 10 });
            };
            return _dfTmp;
        },
        NumberField: function (_id, config) {
            var _sendUpdates = config.sendUpdates;
            delete config.sendUpdates;
            if (!config.isInContainer) {
                config.style['text-align'] = 'right';
            } else {
                config.style = {};
                config.style['text-align'] = 'right';
            };
            var _dfTmp = new Ext.form.NumberField(config);
            if (_sendUpdates === true)
                _dfTmp.on('change', function (tf, newValue, oldValue) { SendToServer(_id, 'Input', config.id, [newValue, tf.isValid()]); });
            return _dfTmp;
        },
        Form: function (_id, config) {
            var _contDiv = Ext.DomHelper.append(config.parent, { tag: 'div', style: { width: config.width + 'px', position: 'relative', top: config.top + 'px', left: config.left + 'px', height: config.height + 'px'} }, true);
            var _frm = new Ext.form.Form({ labelWidth: 75, msgTarget: 'side', height: config.height + 'px' });
            _frm.fieldset({ legend: config.legend });

            _frm.render(_contDiv);

            return _frm;
        },
        ClickHandler: function (itm, evt) {
            SendToServer(itm.id, 'Click', itm.id, null);
        },
        ToggleHandler: function (itm, chk) {
            SendToServer(itm.id, 'Toggle', itm.id, chk);
        },
        Fixed1: function (v) {
            return Ext.num(v, 0).toFixed(1);
        },
        Fixed2: function (v) {
            return Ext.num(v, 0).toFixed(2);
        },
        Fixed3: function (v) {
            return Ext.num(v, 0).toFixed(3);
        },
        SystemWindow: function (url, titulo, width, height) {
            var win = new Ext.Window({
                layout: 'fit',
                width: width || 600,
                height: height || 400,
                plain: true,
                maximizable: true,
                title: titulo || '',
                items: new Ext.ux.IFrameComponent({ url: url })
            });
            win.show();
        }
    }
} ();

Ext.ns('NetJsWire.app');

window.onunload = function () {
    SendRequest("Unload", "Unload", "ClientDocument", true, false);
};

Date.prototype.getDate = function () {
    return this.getUTCDate();
};

Ext.destroyMembers = function (o, arg1, arg2, etc) {
    for (var i = 1, a = arguments, len = a.length; i < len; i++) {
        Ext.destroy(o[a[i]]);
        delete o[a[i]];
    }
};

Ext.ux.BasicDialog = Ext.extend(Ext.Window, {
    initComponent: function () {
        Ext.apply(this, {
            autoDestroy: true,
            plain: false
        });
        this.on('beforeDestroy', this.onBeforeDestroy, this);
        Ext.ux.BasicDialog.superclass.initComponent.call(this);
    },
    onBeforeDestroy: function () {
        Ext.destroyMembers(this, 'header', 'topToolbar', 'bottomToolbar', 'footer', 'lo adMask', 'body', 'bwrap');
        Ext.ux.BasicDialog.superclass.beforeDestroy.call(this);
    },
    close: function () {
        if (this.fireEvent("beforeclose", this) !== false) {
            var t = this.njsid;
            this.hide(null, function () {
                this.fireEvent('close', this);
                try {
                    this.destroy();
                }
                catch (e) { };
            }, this);
            Ext.callback(function () { SendToServer("Window", "Closed", t, null, false, true) }, null, [], 10);
        };
    },
    realClose: function () {
    }
});

Ext.namespace("Ext.ux");
Ext.ux.comboBoxRenderer = function (combo) {
    return function (value) {
        try {
            var idx = combo.store.find(combo.valueField, value);
            var rec = combo.store.getAt(idx);
            return rec.get(combo.displayField);
        }
        catch (e) {
            return null;
        };
    };
};

Ext.ux.NTextField = function (config) {
    // call parent constructor
    Ext.ux.NTextField.superclass.constructor.call(this, config);

    var _sendUpdates = config.sendUpdates;
    delete config.sendUpdates;
    if (_sendUpdates === true)
        this.on('change', function (tf, newValue, oldValue) { SendToServer(config.id, 'Input', config.id, [newValue, tf.isValid()]); });

}; // end of Ext.ux.NTextField constructor

// extend
Ext.extend(Ext.ux.NTextField, Ext.form.TextField, {

}); // end of extend

Ext.reg('ntextfield', Ext.ux.NTextField);

Ext.ux.NTextArea = function (config) {
    // call parent constructor
    Ext.ux.NTextArea.superclass.constructor.call(this, config);

    var _sendUpdates = config.sendUpdates;
    delete config.sendUpdates;
    if (_sendUpdates === true)
        this.on('change', function (tf, newValue, oldValue) { SendToServer(config.id, 'Input', config.id, [newValue, tf.isValid()]); });

}; // end of Ext.ux.NTextField

// extend
Ext.extend(Ext.ux.NTextArea, Ext.form.TextArea, {

}); // end of extend

Ext.reg('ntextarea', Ext.ux.NTextArea);

Ext.ux.NCheckBox = function (config) {
    // call parent constructor
    Ext.ux.NCheckBox.superclass.constructor.call(this, config);

    var _sendUpdates = config.sendUpdates;
    delete config.sendUpdates;
    if (_sendUpdates === true)
        this.on('check', function (chb, chkd) { SendToServer(config.id, 'Check', config.id, chkd, false); });

}; // end of Ext.ux.NTextArea

// extend
Ext.extend(Ext.ux.NCheckBox, Ext.form.Checkbox, {

}); // end of extend

Ext.reg('ncheckbox', Ext.ux.NCheckBox);

Ext.ux.NNumberField = function (config) {
    // call parent constructor
    Ext.ux.NNumberField.superclass.constructor.call(this, config);

    var _sendUpdates = config.sendUpdates;
    delete config.sendUpdates;
    if (_sendUpdates === true)
        this.on('change', function (tf, newValue, oldValue) { SendToServer(config.id, 'Input', config.id, [newValue, tf.isValid()]); });
}; // end of Ext.ux.NNumberField

// extend
Ext.extend(Ext.ux.NNumberField, Ext.form.NumberField, {

}); // end of extend

Ext.reg('nnumberfield', Ext.ux.NNumberField);

Ext.ux.NDateField = function (config) {
    // call parent constructor
    Ext.ux.NDateField.superclass.constructor.call(this, config);

    var _sendUpdates = config.sendUpdates;
    var _format = config.format;
    delete config.sendUpdates;
    if (_sendUpdates === true)
        this.on("change", function (tf, newValue, oldValue) { SendToServer(config.id, "Input", config.id, tf.isValid() ? [Ext.util.Format.date(tf.getValue(), tf.format), true] : [tf.getRawValue(), false]); }, this, { delay: 10 });
};  // end of Ext.ux.NNumberField

// extend
Ext.extend(Ext.ux.NDateField, Ext.form.DateField, {

}); // end of extend

Ext.reg('ndatefield', Ext.ux.NDateField);

Ext.ux.NPanel = function (config) {
    // call parent constructor
    Ext.ux.NPanel.superclass.constructor.call(this, config);
    this.on({
        render: { scope: this, fn: function () {
            if (this.initialConfig.useIFrame === true) {
                var iframe = new Ext.ux.IFrameComponent({ url: this.initialConfig.iframeUrl });
                this.add(iframe);
                this.iframe = iframe;
            }
        }
        }
    });
};  // end of Ext.ux.NDateField

// extend
Ext.extend(Ext.ux.NPanel, Ext.Panel, {
    setIframeUrl: function (url) {
        this.iframe.setIframeUrl(url);
    }
}); // end of extend

Ext.reg('npanel', Ext.ux.NPanel);

Ext.ux.NHtmlEditor = function (config) {
    // call parent constructor
    Ext.ux.NHtmlEditor.superclass.constructor.call(this, config);
    /*
    this.on("beforepush", function (h, v) {
    h.getEditorBody().innerHTML = unescape(v);
    if (Ext.isGecko) {
    // Gecko hack, see: https://bugzilla.mozilla.org/show_bug.cgi?id=232791#c8
    h.setDesignMode(false);  //toggle off first
    h.setDesignMode(true);
    }
    h.fireEvent('push', h, v);
    return false;
    });
    */
};  // end of Ext.ux.NHtmlEditor

// extend
Ext.extend(Ext.ux.NHtmlEditor, Ext.form.HtmlEditor, {

}); // end of extend

Ext.reg('nhtmleditor', Ext.ux.NHtmlEditor);


Ext.form.ComboBox.prototype.assertValue = function () {
    var val = this.getValue(),
    rec = this.findRecord(this.valueField, val);

    if (!rec && this.forceSelection) {
        val = this.getRawValue();
        if (val.length > 0 && val != this.emptyText) {
            this.el.dom.value = Ext.value(this.lastSelectionText, '');
            this.applyEmptyText();
        } else {
            this.clearValue();
        }
    } else {
        if (rec) {
            val = rec.get(this.valueField || this.displayField);
        }
        this.setValue(val);
    }
};